--Template Method
--[[
	模板方法：（行为型）
	作用：抽离出一个基类，将共有逻辑放入基类，便于逻辑复用
	使用场景：逻辑框架相同，具体实现不同时，可以将逻辑框架放入基类，由子类实现
	例子：Skill Module
--]]

require 'Class'

DeployerBase = Class()  --部署器基类
DeployerBase.Deploy = function(self,params)
	self:SearchTarget(params)
	self:DoLogic(params)
	self:DoView(params)
end
DeployerBase.SearchTarget = function(self,params)end
DeployerBase.DoLogic = function(self,params)end
DeployerBase.DoView = function(self,params)end

SkillDeployer = Class(DeployerBase)
SkillDeployer.SearchTarget = function(self,params)
	print(string.format('搜索%s攻击目标：%s',params.searchType,params.targetName))
end
SkillDeployer.DoLogic = function(self,params)
	print(string.format('计算%s伤害：%d',params.deployerType,params.damage))
end
SkillDeployer.DoView = function(self,params)
	print(string.format('释放特效：%s',params.effect))
end

NormalAtkDeployer = Class(DeployerBase)
NormalAtkDeployer.SearchTarget = function(self,params)
	print(string.format('搜索%s攻击目标：%s',params.searchType,params.targetName))
end
NormalAtkDeployer.DoLogic = function(self,params)
	print(string.format('计算%s伤害：%d',params.deployerType,params.damage))
end
NormalAtkDeployer.DoView = function(self,params)
	print(string.format('释放特效：%s',params.effect))
end

--------Main--------
function  main()
	skillData = {
		deployerType = 'Skill',
		searchType = '群体',
		targetName = '五级小兵',
		damage = 25,
		effect = '寒冰之握',
	}
	normalAtkData = {
		deployerType = 'normalAtk',
		searchType = '单体',
		targetName = '一级小兵',
		damage = 15,
		effect = '近战攻击特效',
	}
	skillDeployer = SkillDeployer:New()
	normalAtkDeployer = NormalAtkDeployer:New()

	skillDeployer:Deploy(skillData)  --搜索群体攻击目标：五级小兵
									 --计算Skill伤害：25
									 --释放特效：寒冰之握

	normalAtkDeployer:Deploy(normalAtkData)  --搜索单体攻击目标：一级小兵
											 --计算normalAtk伤害：15
											 --释放特效：近战攻击特效
end

main()
